Objective-C Memory Management: When do I [release]?

Posted by Sahat on Stack Overflow See other posts from Stack Overflow or by Sahat
Published on 2010-06-10T06:05:58Z Indexed on 2010/06/10 6:22 UTC
Read the original article Hit count: 364

I am still new to this Memory Management stuff (Garbage Collector took care of everything in Java), but as far as I understand if you allocate memory for an object then you have to release that memory back to the computer as soon as you are finished with your object.

myObject = [Object alloc];

and

[myObject release];

Right now I just have 3 parts in my Objective-C .m file: @Interface, @Implementation and main. I released my object at the end of the program next to these guys:

[pool drain];
return 0;

But what if this program were to be a lot more complicated, would it be okay to release myObject at the end of the program?

I guess a better question would be when do I release an object's allocated memory? How do I know where to place [myObject release];?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about memory-management